<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Title</title>
  </head>
  <body>
    <div id="app">
      <div id="msg">123</div>
      <button onclick="clickButton()">点击</button>
    </div>
  </body>
  <script type="application/javascript">
    const token = '';

    let elementForMsg = document.getElementById('msg');

    // window.onload = function() {
    //   elementForMsg = document.getElementById("msg");
    // }

    function clickButton() {
      const data = {
        clientid: 'sn-XN013496017',
        username: 'XN013496017',
        password: '2ed639f4b691f76dd2006680c20e93f2',
      };

      fetch('http://sit-cn.hero-ee.com:8002/api/emqx/hook/auth', {
        method: 'POST',
        body: JSON.stringify(data),
        headers: {
          'content-type': 'application/json;charset=UTF-8',
          Authorization: token,
        },
      })
        .then(function (response) {
          return response.json();
        })
        .then(function (json) {
          elementForMsg.innerText = json;
        })
        .catch((e) => {
          elementForMsg.innerText = e;
        });
    }
  </script>
  <script></script>
</html>
